﻿<?php
   session_start();
   $companyName=$_POST["companyName"];
   $CName=$_POST["CName"];
   $password=$_POST["password"];
   $re_password=$_POST["re_password"];
   include ("../class/filter.class.php");
   $myfilter=new filter();
   
   //处理企业名称
   $companyName=$myfilter->Filter_Input($companyName);
   $length=strlen($companyName);
   if($length<1)
   {
   	  echo '<script>alert("企业名称不能为空！");window.location.href="../admin/Add_Recruitment_Info.php"</script>';
   	  exit();
   }
   
    //处理账号
   $CName=$myfilter->Filter_Input($CName);
   $length=strlen($CName);
   if($length<3||$length>32)
   {
   	 echo'<script>alert("账号长度必须大于3-32位之间");window.location.href="../admin/Add_Recruitment_Info.php"</script>';
   	 exit();
   }
   
   //处理密码
   if($password!=$re_password)
   {
     echo '<script>alert("两次密码不相同，请重新输入！");window.location.href="../admin/Add_Recruitment_Info.php"</script>';
     exit();
   }
   else 
   {
   	  $password=$myfilter->Filter_Input($password);
   	  $length=strlen($password);
   	  if($length<6)
   	  {
   	  	echo '<script>alert("密码长度必须大于6位！");window.location.href="../admin/Add_Recruitment_Info.php"</script>';
   	  	exit();
   	  }
   }
   //包含进企业类
   include ("../class/company.class.php");
   $Company = new Company();
   if($Company->IsNameExist($CName))
   {
   	  echo '<script>alert("用户名已存在，请重新输入！");window.location.href="../admin/Add_Recruitment_Info.php"</script>';
   	  exit(); 
   }
   else 
   {
   		
   	  $newId=$Company->UserAdd($CName,$password,$companyName);
   	  if($newId>-1)
   	  {
   	  	$Company->login($CName, $password);
   	  	echo '<script>alert("注册成功！");window.location.href="../admin/manage.php";</script>';
   	  }
   	  else {
   	  	echo '<script>alert("注册失败！");window.location.href="../admin/Add_Recruitment_Info.php";</script>';
   	  }
   }
   

?>